﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBMigrator.Core.DbObjects.Data.Insert;
using Xunit;

namespace DBMigrator.Core.Tests.DbObjects.Data
{
    public class InsertTests
    {
        private List<object> values;

        public InsertTests()
        {
            values = new List<object>
                         {
                             "Test"
                         };
        }

        [Fact]
        public void SqlGenerationTypeShouldReturnIInsert()
        {
            Assert.Equal(typeof(IInsert<object>), new Insert<object>("TableName", values).SqlGenerationType);
        }

        [Fact]
        public void ConstructorShouldThrowIfTableNameIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Insert<object>(null, values));
        }

        [Fact]
        public void ConstructorShouldThrowIfTableNameIsEmpty()
        {
            Assert.Throws<ArgumentNullException>(() => new Insert<object>(string.Empty, values));
        }

        [Fact]
        public void ConstructorShouldSetTableName()
        {
            var tableName = StringUtil.Random();
            Assert.Equal(tableName, new Insert<object>(tableName, values).TableName);
        }

        [Fact]
        public void ConstructorShouldThrowIfValuesIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Insert<object>("TableName", null));
        }

        [Fact]
        public void ConstructorShouldThrowIfValuesIsEmpty()
        {
            values.Clear();
            Assert.Throws<ArgumentException>(() => new Insert<object>("TableName", values));
        }

        [Fact]
        public void ConstructorShouldSetValues()
        {
            Assert.Equal(values, new Insert<object>("TableName", values).Values);
        }
    }
}
